/**
 * BROKE提示词模板插件
 * type: templatePlugin
 * 结构参考：https://api-docs.deepseek.com/zh-cn/api/create-chat-completion
 * 适配BROKE五步法：Background/Role/Objectives/Key Points/Evolve
 */
module.exports = class BrokePromptTemplatePlugin {
  constructor(options = {}) {
    this.type = 'templatePlugin';
    this.name = 'broke';
    this.version = '1.1.0';
    this.description = 'BROKE范式提示词模板，提升AI交互深度与精度（沙盒适配版）';
    
    console.log('[BrokePlugin] 沙盒模式初始化', {
      type: this.type,
      version: this.version
    });
  }

  /**
   * 获取form-create规则
   * @returns {Array} 表单规则
   */
  getPromptRule() {
    return [
      {
        type: 'textarea',
        field: 'background',
        title: 'Background（背景）',
        value: '',
        props: {
          placeholder: '请输入任务或问题的背景信息，有助于模型理解上下文。例如：我们正在开发一款面向青少年的学习App。',
          rows: 3,
          resize: 'none',
          maxlength: 11200,
          showWordLimit: true,
          style: 'width:100%'
        },
        col: { span: 24 },
        labelPosition: 'top',
        validate: [{ 
          required: true, 
          message: '请输入背景信息',
          trigger: 'blur'
        }]
      },
      {
        type: 'textarea',
        field: 'role',
        title: 'Role（角色）',
        value: '',
        props: {
          placeholder: '请输入AI在任务中的角色。例如：你是一位教育专家，擅长青少年心理辅导。',
          rows: 2,
          resize: 'none',
          maxlength: 11200,
          showWordLimit: true,
          style: 'width:100%'
        },
        col: { span: 24 },
        labelPosition: 'top',
        validate: [{ 
          required: true, 
          message: '请输入角色信息',
          trigger: 'blur'
        }]
      },
      {
        type: 'textarea',
        field: 'objectives',
        title: 'Objectives（目标）',
        value: '',
        props: {
          placeholder: '请输入具体目标或期望结果。例如：请为该App设计一套激励机制，提升用户学习积极性。',
          rows: 3,
          resize: 'none',
          maxlength: 11200,
          showWordLimit: true,
          style: 'width:100%'
        },
        col: { span: 24 },
        labelPosition: 'top',
        validate: [{ 
          required: true, 
          message: '请输入目标',
          trigger: 'blur'
        }]
      },
      {
        type: 'textarea',
        field: 'keyPoints',
        title: 'Key Points（关键点）',
        value: '',
        props: {
          placeholder: '请输入需要特别关注的关键信息或数据。例如：用户年龄段为12-18岁，需兼顾趣味性与科学性。',
          rows: 3,
          resize: 'none',
          maxlength: 11200,
          showWordLimit: true,
          style: 'width:100%'
        },
        col: { span: 24 },
        labelPosition: 'top'
      },
      {
        type: 'textarea',
        field: 'evolve',
        title: 'Evolve（改进）',
        value: '',
        props: {
          placeholder: '如有，请输入对AI回答的改进建议或优化方法。例如：请在回答后给出进一步提升用户粘性的建议。',
          rows: 2,
          resize: 'none',
          maxlength: 11200,
          showWordLimit: true,
          style: 'width:100%'
        },
        col: { span: 24 },
        labelPosition: 'top'
      }
    ];
  }

  /**
   * 根据表单数据生成BROKE范式提示词内容
   * @param {Object} formData 表单数据
   * @returns {String} 生成的提示词内容
   */
  getPromptContent(formData) {
    let content = '';
    if (formData.background) content += `【背景】${formData.background}\n\n`;
    if (formData.role) content += `【角色】${formData.role}\n\n`;
    if (formData.objectives) content += `【目标】${formData.objectives}\n\n`;
    if (formData.keyPoints) content += `【关键点】${formData.keyPoints}\n\n`;
    if (formData.evolve) content += `【改进】${formData.evolve}`;
    return content.trim();
  }
}
